package controller;

import service.HomeService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet("/home/*")
public class HomeServlet extends BaseServlet{
    private HomeService homeService = new HomeService();


    protected void index(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //1.查询今日数据
        Map<String,Object> homeCount = homeService.findHomeCount();

        //2.查询近七日数据
        List<List<Integer>> homeDetail = homeService.findHomeDetail();

        //包装成一个Map响应到前端
        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("homeCount",homeCount);
        resultMap.put("homeDetail",homeDetail);

        //转成JSON写到前端
        writerObjToString(resp,resultMap);



    }
}
